<?php

namespace App\Admin\Extensions\Nav;

use App\Models\AdminRoleMenuModel;
use App\Models\AdminRoleModel;
use App\Models\AdminRoleUserModel;
use App\Models\AdminUserModel;
use App\Models\CommonModel;
use App\Models\DataDictionaryModel;
use App\Models\MessageNotificationModel;
use Encore\Admin\Facades\Admin;

class Help
{
    public function __toString()
    {
        $user_role_data = AdminRoleUserModel::where(['user_id'=>Admin::user()->id])->first();

        $list = MessageNotificationModel::where(['notifier_id'=>$user_role_data['role_id'],'is_handled'=>0])->offset(0)->limit(5)->orderBy('created_at', 'DESC')->get();

        $str = "";
        foreach($list as $item){

            $qian = CommonModel::format_date(strtotime($item['created_at']));
            $route_address = DataDictionaryModel::MessageRoute[$item['route_url']];

            $str.='<li class="xiaoxi">';
                $str.='<a href="'.$route_address.'">';
                     $str.='<div class="li-content">';
                        $str.='<h5 class="li-h5">'.$item['name'].'</h5>';
                        $str.='<p class="li-p">'.$item['detail'].'</p>';
                     $str.='</div>';
                     $str.='<div class="shijian">';
                        $str.='<span><i class="fa fa-clock-o"></i>&nbsp;'.$qian.'</span>';
                     $str.='</div>';
                $str.='</a>';
            $str.='</li>';
        }
        $count = MessageNotificationModel::where(['notifier_id'=>$user_role_data['role_id'],'is_handled'=>0])->count();

        return <<<HTML
<li>
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
          <i class="fa fa-bell-o"></i>
          <span class="label label-danger">{$count}</span>
    </a>
    <ul class="dropdown-menu" style="min-width: 340px;height: 400px;">
         <li class="li-header herder">您有{$count}个待办事项</li>
           {$str}
         <!--<a href="/admin/my/message"><li class="footer li-header" >全部</li></a>-->
     </ul>
</li>

<style>
.li-header{
    background-color: #1890ff;
    text-align: center;
    border-radius: 4px;
    height: 45px;
    line-height: 40px;
    color: white;
    margin: 0 10px;
}
.xiaoxi{
    list-style-type:none;
    height: 60px;
    line-height: 65px;
    border-bottom: 1px solid #aaa;
    width: 90%;
    margin-left: 5%;
}
.li-content{
    width: 80%;
    float: left;
    line-height: 10px;
}
.li-p{
    color: #999;
    font-size: 12px;
}
.shijian{
    line-height: 50px;
}
.li-h5{
    color: black;
}
</style>

HTML;
    }
}